package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Code int         `json:"code"` // 自定义数据信息
	Msg  string      `json:"msg"`  //
	Data interface{} `json:"data"`
}

func SuccessWithMsg(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, Response{
		Code: http.StatusOK,
		Msg:  msg,
	})
}

func FailWithMsg(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, Response{
		Code: http.StatusInternalServerError,
		Msg:  msg,
	})
}

// SuccessWithTotal 成功处理，并返回信息
func SuccessWithTotal(c *gin.Context, msg string, data interface{}) {
	c.JSON(http.StatusOK, Response{
		Code: http.StatusOK,
		Msg:  msg,
		Data: data,
	})
}

func NoAuth(c *gin.Context, msg string) {
	// 401表示未授权
	c.JSON(http.StatusOK, Response{
		Code: http.StatusUnauthorized,
		Msg:  msg,
	})
}
